//
//  DKHomeMsgAlertView.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/12/8.
//

#import "DKHomeMsgAlertView.h"
#import "DKMsgAlertCollectionCell.h"
@interface DKHomeMsgAlertView()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *msgSycleScrollView;
@property (nonatomic,strong) NSMutableArray *orderStatus;
@end
@implementation DKHomeMsgAlertView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.clearColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    _msgSycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds imageNamesGroup:@[]];
    _msgSycleScrollView.backgroundColor = [UIColor clearColor];
    _msgSycleScrollView.autoScroll = YES;
    _msgSycleScrollView.delegate = self;
    _msgSycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _msgSycleScrollView.infiniteLoop = YES;
    _msgSycleScrollView.showPageControl = NO;
    _msgSycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
    [self addSubview:_msgSycleScrollView];
    [_msgSycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
}
- (void)updataOrderMsg{
    DKOrderStatusModel *orderStatusMdl = [DKGlobalHelper defaultManager].orderStatusMdl;
    self.orderStatus = [[NSMutableArray alloc] init];
    if([orderStatusMdl.settled isEqualToString:@"1"]){
        [self.orderStatus addObject:@"1"];
    }
    if([orderStatusMdl.underReview isEqualToString:@"1"]){
        [self.orderStatus addObject:@"0"];
    }
    if(self.orderStatus.count > 0){
        _msgSycleScrollView.imageURLStringsGroup = self.orderStatus;
    }else{
        if(self.MsgAlertHidBlock){
            self.MsgAlertHidBlock();
        }
    }
}
#pragma mark -- SDCycleScrollViewDelegate
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
    return [DKMsgAlertCollectionCell class];
}
// 设置数据
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
    WeakSelf(self)
    DKMsgAlertCollectionCell *dk_MsgAlertCollectionCell = (DKMsgAlertCollectionCell *)cell;
    dk_MsgAlertCollectionCell.settled = self.orderStatus[index];
    dk_MsgAlertCollectionCell.MsgAlertGoBlock = ^(NSString * _Nonnull settled) {
        if(weakSelf.MsgAlertGoBlock){
            weakSelf.MsgAlertGoBlock(settled);
        }
        for (int i = 0; i < weakSelf.orderStatus.count; i++) {
            NSString *orderSettled = weakSelf.orderStatus[i];
            if([orderSettled isEqualToString:settled]){
                [weakSelf.orderStatus removeObjectAtIndex:i];
            }
        }
        if(weakSelf.orderStatus.count > 0){
            weakSelf.msgSycleScrollView.imageURLStringsGroup = weakSelf.orderStatus;
        }else{
            if(weakSelf.MsgAlertHidBlock){
                weakSelf.MsgAlertHidBlock();
            }
        }
    };
    dk_MsgAlertCollectionCell.MsgAlertCloseBlock = ^(NSString * _Nonnull settled) {
        for (int i = 0; i < weakSelf.orderStatus.count; i++) {
            NSString *orderSettled = weakSelf.orderStatus[i];
            if([orderSettled isEqualToString:settled]){
                [weakSelf.orderStatus removeObjectAtIndex:i];
            }
        }
        if(weakSelf.orderStatus.count > 0){
            weakSelf.msgSycleScrollView.imageURLStringsGroup = weakSelf.orderStatus;
        }else{
            if(weakSelf.MsgAlertHidBlock){
                weakSelf.MsgAlertHidBlock();
            }
        }
    };
}
@end
